

namespace NeuralNetworks.Networks
{
	using System;
    using NeuralNetworks;
    using NeuralNetworks.Layers;

	/// <summary>
	/// Base neural network class
	/// </summary>
	/// 
	/// <remarks>This is a base neural netwok class, which represents
	/// collection of neuron's layers.</remarks>
	/// 
	public abstract class Network
	{
        Layer[] layers;

        public int LayersCount { get { return layers.Length; } }

	    public virtual void RandomWeights(double min, double max)
        {
            Random rand = new Random();
            for (int i = 0; i < layers.Length; i++)
            {
                layers[i].RandomWeights(rand);
            }
        }

	    public abstract void ZeroWeights();

        public virtual double[] Compute(double[] x)
        {
            if ((x == null) || (x.Length != layers[0].Neurons.Count))
            { throw (new NeuralNetworksException()); };

            layers[0].SetOutputs(x);
            for (int i = 0; i < layers.Length; i++)
            {
                layers[i].Compute();
            }
            int lastLayer = layers.Length - 1;
            layers[lastLayer].Compute();
            return layers[lastLayer].Outputs();
        }
    }
}
